<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        const ac = new AbortController();
        const signal = ac.signal;
        signal.addEventListener('abort', () => console.log('请求已取消'));
        fetch('/api/data', { signal }).then((res) => res.json()).then((data) => console.log(data));
        // 取消请求
        ac.abort();
    </script>
</body>
</html>